package test;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class AlphaComp implements Comparator {
public int compare(Object o1, Object o2) {
// Assume it's used only for Strings...
String s1 = ((String)o1).toLowerCase();
String s2 = ((String)o2).toLowerCase();
return s1.compareTo(s2);
}
@SuppressWarnings("unchecked")
public static void main(String[] args) {
String[] s = {"zdf","gsg","rsfs","fsdfsd"};
List<String> list = Arrays.asList(s);
AlphaComp ac = new AlphaComp();
Collections.sort(list, ac);
Arrays.sort(s, ac);
// Must use the Comparator to search, also:
int loc = Arrays.binarySearch(s, s[3], ac);
System.out.println("Location of " + s[3] +
" = " + loc);
}
}
